package javaJob.exercise.primary.string;


/***
 * 暴力解法
 */

public class primary12 {
    public static void main(String[] args) {
//        double a = Math.pow(2,32);
//        System.out.println(a);
//        int b=1000;
//        double c = b;
//        System.out.println(c);
//        System.out.println(a>c);
//        System.out.println(Math.pow(2,31)-1);
        System.out.println((int)(0-Math.pow(2,31)));
        int x = -120;
        int xx=1534236469;
        int xxx=-2143847412;
        System.out.println(reverse(xxx));
    }

    static int reverse(int x) {
        int answer=0;
        int tag=0;
        int in=0;
        Integer max=(int)Math.pow(2,31)-1;
        Integer min=0-(int)Math.pow(2,31);
        char[] num = Integer.valueOf(x).toString().toCharArray();
        char[] max_char = max.toString().toCharArray();
        char[] min_char = min.toString().toCharArray();
        int[] num1 = new int[num.length];


        for (int i=0;i<num.length;i++){//输出
                System.out.print(num[i]);
            }
        System.out.println("");

        if (num[0]!='-'){
            System.out.println("正数");
            tag=0;
            for (int i=0;i<num.length;i++){
                num1[i]=Character.getNumericValue(num[i]);//该方法将char中数字元素转为int类型
            }
        }else {
                System.out.println("负数");
                tag=-1;
                for (int i=0;i<num.length-1;i++){
                    num1[i]=Character.getNumericValue(num[i+1]);//该方法将char中数字元素转为int类型
                    System.out.print(num1[i]);
                }
                System.out.println("");
                num1[num.length-1]=0;
        }


        for (int i=0;i<num1.length/2;i++){
                int temp=num1[i];
                num1[i]=num1[num1.length-(i+1)];
                num1[num1.length-(i+1)]=temp;
            }

        for (int i=0;i<num1.length;i++){//输出
            System.out.print(num1[i]);
            System.out.println("-");
        }
        System.out.println("");


        if (tag==0){//正数
            System.out.println("正数");
            int[] max_int = new int[max_char.length];
            for (int i=0;i<max_char.length;i++){
                max_int[i]=Character.getNumericValue(max_char[i]);
            }
            if (max_int.length>num1.length){
                for (int i=0;i<num1.length;i++){
//                System.out.println((int)Math.pow(10,(num1.length-(i+1))));
                    answer=answer+num1[i]*((int)Math.pow(10,(num1.length-(i+1))));
                }
                answer=answer+0;
            }else if (max_int.length==num1.length){
                for (int i=0;i<max_int.length;i++){
                    if (max_int[i]==num1[i]){
                        continue;
                    }else if (max_int[i]>num1[i]){
                        in=0;
                        break;
                    }else if (max_int[i]<num1[i]){
                        in=-1;
                        answer=0;
                        break;
                    }
                }
                if (in==0){
                    for (int i=0;i<num1.length;i++){
//                System.out.println((int)Math.pow(10,(num1.length-(i+1))));
                        answer=answer+num1[i]*((int)Math.pow(10,(num1.length-(i+1))));
                    }
                    answer=answer+0;
                }else {
                    answer=0;
                }
            }else {
                answer=0;
            }
        }else {//负数
            System.out.println("负数");
            int[] min_int = new int[min_char.length-1];
            for (int i=0;i<min_char.length-1;i++){
                min_int[i]=Character.getNumericValue(min_char[i+1]);
            }
            if (min_int.length+1>num1.length){
                for (int i=0;i<num1.length;i++){
//                System.out.println((int)Math.pow(10,(num1.length-(i+1))));
                    answer=answer+num1[i]*((int)Math.pow(10,(num1.length-(i+1))));
                }
                answer=0-answer;
            }else if (min_int.length+1==num1.length){
                for (int i=0;i<min_int.length;i++){
                    if (min_int[i]==num1[i+1]){
                        System.out.println("-"+i);
                        continue;
                    }else if (min_int[i]>num1[i+1]){
                        in=0;
                        System.out.println("--"+i);
                        break;
                    }else if (min_int[i]<num1[i+1]){
                        in=-1;
                        answer=0;
                        System.out.println("---"+i);
                        break;
                    }
                }
                if (in==0){
                    for (int i=0;i<num1.length;i++){
//                System.out.println((int)Math.pow(10,(num1.length-(i+1))));
                        answer=answer+num1[i]*((int)Math.pow(10,(num1.length-(i+1))));
                    }
                    answer=0-answer;
                }else {
                    answer=0;
                }
            }else {
                answer=0;
            }
        }



//        if (tag==0){
//                answer=answer+0;
//            }else {
//                answer=0-answer;
//            }

        return answer;
    }

}
